<?

/*
*
*   Excalibur Content Management System
*   Copyright © 2008 Egor "Sontan" Kuryanovich
*
*   Based on Explay Engine v2.0 by Golovdinov Alexander
*
*   Official site: www.excms.ru
*   Contact e-mail: support@excms.ru
*
*   GNU General Public License original source:
*   http://www.gnu.org/licenses/gpl-3.0.html
*
*/


if (isset($_COOKIE['login']) && isset ($_COOKIE['pass']) && $_COOKIE['login'] != "false" && $_COOKIE['pass'] != "false") {
	$GLOBAL_USER_LOGIN = addslashes($_COOKIE['login']);
	$GLOBAL_USER_PASS = addslashes($_COOKIE['pass']);
	if ($GLOBAL_USER_LOGIN != "" && $GLOBAL_USER_PASS != "")
		$SELECT_USER = $db->query ("SELECT * FROM ".DB_PEREFIX."_users WHERE user_login = '$GLOBAL_USER_LOGIN' && user_password = '$GLOBAL_USER_PASS'");
	if ($db->num_rows ($SELECT_USER) == 1) {
		$GLOBAL_USER = $db->fetch_array ($SELECT_USER);
	}
}

if (!is_registered() || !is_numeric(_get(2))) error_403();

$SITE_get = $db->query ('SELECT * FROM site_main');
$SITE = $db->fetch_array ($SITE_get);
$theme = $SITE['site_theme'];

require_once $_SERVER['DOCUMENT_ROOT'].'/modules/system/classes/templates.class.php';
$template = new template ($_SERVER['DOCUMENT_ROOT'].'/themes/'.$theme.'/');
$template->user = 'register';

$id = intval (_get(2));

$get = $db->query ('SELECT user_name, user_karma, voters FROM '.DB_PEREFIX."_users WHERE user_id = '$id'");

if ($db->num_rows ($get) == 0) error_404 ();

list ($user_name, $karma, $voters) = $db->fetch_row ($get);
$voters = explode (',', $voters);

$good = '';
$bad = '';

foreach ($voters as $v) 
{
	$v = explode ("=", $v);
	$get_user = $db->query ("SELECT user_name FROM ".DB_PEREFIX."_users WHERE user_id = '{$v[0]}'");
	
	if ($db->num_rows ($get_user) == 1) 
	{
		list ($name) = $db->fetch_row ($get_user);
		if ($v[1] == 1) 
			$good .= '<li class="friend"><a href="/users/'.$v[0].'.html">'.$name."</a></li>\n";
		else 
			$bad.= '<li class="friend"><a href="/users/'.$v[0].'.html">'.$name."</a></li>\n";
	}
}

$template->set_var ('{GOOD}','<ul class="friends_list">'.$good.'</ul>');
$template->set_var ('{BAD}', '<ul class="friends_list">'.$bad.'</ul>');
$template->set_var ('{USER_NAME}', $user_name);
$template->set_var ('{KARMA}', number_format ($karma, 2, ',', ''));

echo $template->display ('user_voters.tpl');
